﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace FCNS.KeepMoney.Forms
{
    public partial class ParentForm : Form
    {
        public ParentForm()
        {
            InitializeComponent();
        }

        public virtual void SetControlLocation(Control leftC, Control rightC)
        {
            if (Program.AppConfig.App.Language == KeepMoney.Configuration.AppDefines.defaultLanguage)
                return;

            int left = (this.Width - leftC.Width - rightC.Width) / 2-5;
            leftC.Left = left < 0 ? 0 : left;
            rightC.Left = leftC.Width+ left+10;
        }

        public virtual void SetControlLocation(Control[] controls)
        {
            int left = 0;
            int space = 0;
            foreach (Control c in controls)
                space += c.Width;

            if (this.Width < space)
                this.Width = space + controls.Length * 5;

            space = (this.Width - space) / (controls.Length+1);

            foreach (Control c in controls)
            {
                c.Left = left + space;
                left = c.Width + c.Left;
            }
        }

        public virtual void SetControlLocation(List<Control[]> controls)
        {
            if (Program.AppConfig.App.Language == KeepMoney.Configuration.AppDefines.defaultLanguage)
                return;

            //求出居中点
            int min = 0;
            int rLeft = 0;
            foreach (Control[] cs in controls)
            {
                int i = cs[0].Width + cs[1].Width;
                if (min < i)
                {
                    min = i;
                    rLeft = (this.Width - i) / 2 + cs[0].Width;
                }
            }

            foreach (Control[] cs in controls)
            {
                cs[0].Left = rLeft - cs[0].Width;
                cs[1].Left = rLeft + 5;
            }
        }

        //private void OnFormLoad(object sender, EventArgs e)
        //{
        //    if (DesignMode)
        //        return;

        //    if (Program.AppConfig.MainForm.FormTheme == "操作系统")
        //        return;

        //    //ThemeManager theme = new ThemeManager(Program.AppConfig.MainForm.FormTheme);
        //    //if (theme.themeOk)
        //    //    theme.ApplyTheme(this);
        //    //else
        //    //    Program.TheMainForm.notifyIcon1.ShowBalloonTip(30000, "",
        //    //        "样式文件损坏,以默认样式显示", ToolTipIcon.Error);
        //}
    }
}
